package com.yhd.gmall.user.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yhd.gmall.model.user.UserInfo;
import com.yhd.gmall.user.mapper.UserInfoMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
 * @author yhd
 * @createtime 2020/9/25 19:26
 */
@Service
public class UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 登录
     */
    public UserInfo login(UserInfo userInfo) {
        //将传进来的密码进行加密
        if (userInfo != null) {
            String newPwd = DigestUtils.md5DigestAsHex(userInfo.getPasswd().getBytes());
            QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("login_name", userInfo.getLoginName());
            queryWrapper.eq("passwd", newPwd);
            UserInfo info = userInfoMapper.selectOne(queryWrapper);
            if (info != null) {
                return info;
            }
        }
        return null;
    }
}
